package com.spbdx.system.service.rocketmq;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

/**
 * @author chenwei
 * @version 1.0
 * @date 2024/1/8 16:36
 */
@Service
@Slf4j
@ConditionalOnProperty(name = "rocketmq.name-server")
@RocketMQMessageListener(topic = "common", consumerGroup = "common-consumer-group1"/*, consumeMode = ConsumeMode.ORDERLY*/)
public class MqConsumeService implements RocketMQListener<String>, RocketMQPushConsumerLifecycleListener {

    @Override
    public void onMessage(String str) {

    }

    @Override
    public void prepareStart(DefaultMQPushConsumer defaultMQPushConsumer) {
        // 设置最大重试次数
        defaultMQPushConsumer.setMaxReconsumeTimes(3);
    }
}

